﻿using Coldairarrow.Business.Base_Manage;
using Coldairarrow.Entity.Base_Manage;
using Coldairarrow.Util;
using Coldairarrow.Util.Utilities;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NSwag.Annotations;
using System.Collections.Generic;
using System.Threading.Tasks;



namespace Coldairarrow.Api.Controllers.Base_Manage
{
    [Route("/Base_Manage/[controller]/[action]")]
    [NoApiPermission]
    [OpenApiTag("Base_Api")]
    public class Base_ApiController : BaseApiController
    {
        #region DI

        public Base_ApiController(IBase_ApiBusiness Base_ApiBus)
        {
            _Base_ApiBus = Base_ApiBus;
        }

        IBase_ApiBusiness _Base_ApiBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<Base_Api>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _Base_ApiBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<Base_Api> GetTheData(IdInputDTO input)
        {
            return await _Base_ApiBus.GetTheDataAsync(input.Id);
        }
        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<string> ExPort(PageInput<ConditionDTO> input)
        {
            return await _Base_ApiBus.ExPortToExcel(input);
        }
        /// <summary>
        /// 导入
        /// </summary>
        /// <param name="files"></param>
        /// <returns></returns>
        [HttpPost]
        public WebResponseContent ImportToExcel(List<IFormFile> files)
        {
            return  _Base_ApiBus.ImportToExcel(files);
        }

        
        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(Base_Api data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _Base_ApiBus.AddDataAsync(data);
            }
            else
            {
                await _Base_ApiBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData2(List<string> ids)
        {
            await _Base_ApiBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}